<%-- 
    Document   : index
    Created on : Nov 23, 2014, 1:59:59 PM
    Author     : Marian Lorenc, 374122
--%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><fmt:message key="customer.title" /></title>
    </head>
    <body>
        <div class="container">
            <h1><fmt:message key="customer.title" /></h1>
            <div>
                <a href="<c:url value="/customer/add"/>">
                    <img src="<c:url value="/resources/pictures/add.png" />" title="<fmt:message key="customer.addNew" />" /> <fmt:message key="customer.addNew" />
                </a>
            </div>

            <c:if test="${empty model.customers}">
                <c:if test="${empty model.search}">
                    <fmt:message key="customer.noCustomers" />
                </c:if>
                <c:if test="${not empty model.search}">
                    <fmt:message key="customer.noCustomersFound" />
                </c:if>
            </c:if>
            <c:if test="${not empty model.customers}"> 	

                <form method="POST" class="form-inline" role="form">
                    <div class="form-group">
                        <label><fmt:message key="customer.searchBy" /></label>
                        <select name="searchBy" id="searchBy" class="form-control">
                            <option value="lastName" <c:if test="${empty model.searchBy}"> selected="selected"</c:if> <c:if test="${model.searchBy == 'lastName'}"> selected="selected"</c:if>><fmt:message key="customer.lastname" /></option>
                            <option value="email" <c:if test="${model.searchBy == 'email'}"> selected="selected"</c:if>><fmt:message key="customer.email" /></option>
                            <option value="companyNumber" <c:if test="${model.searchBy == 'companyNumber'}"> selected="selected"</c:if>><fmt:message key="customer.companynumber" /></option>
                            </select>
                        </div>
                        <div class="form-group">
                            <input class="form-control" type="text" name="search" <c:if test="${not empty model.search}"> value="${model.search}"</c:if>>
                        </div>
                        <div class="form-group">
                            <input type="submit" class="btn btn-default" value="<fmt:message key="search"/>">
                    </div>
                </form>

                <table class="table table-striped">
                    <th>
                        <fmt:message key="detail" />
                    </th>
                    <th>
                        <fmt:message key="customer.firstname" />
                    </th>
                    <th>
                        <fmt:message key="customer.lastname" />
                    </th>
                    <th>
                        <fmt:message key="customer.email" />
                    </th>
                    <th>
                        <fmt:message key="customer.phone" />
                    </th>
                    <th>
                        <fmt:message key="customer.address" />
                    </th>
                    <th>
                        <fmt:message key="customer.type" />
                    </th>
                    <th>
                        <fmt:message key="customer.vat" />
                    </th>
                    <th>
                        <fmt:message key="customer.companynumber" />
                    </th>
                    <th>
                        <fmt:message key="edit" />
                    </th>
                    <c:forEach var="c" items="${model.customers}">
                        <tr>
                            <td>
                                <a href="<c:url value="/customer/detail/${c.id}"/>">
                                    <img src="<c:url value="/resources/pictures/detail.png" />" title="<fmt:message key="detail" />" /> <fmt:message key="detail" />
                                </a>
                            </td>
                            <td>                            
                                <a href="<c:url value="/customer/detail/${c.id}"/>"><c:out value="${c.firstName}"/></a>
                            </td>
                            <td>
                                <a href="<c:url value="/customer/detail/${c.id}"/>"><c:out value="${c.lastName}"/></a>
                            </td>
                            <td>
                                <c:out value="${c.email}"/>
                            </td>
                            <td>
                                <c:out value="${c.phone}"/>
                            </td>                        
                            <td>
                                <c:out value="${c.street}, "/>
                                <c:out value="${c.city}, "/>
                                <c:out value="${c.zipCode}, "/>
                                <c:out value="${c.country}"/>
                            </td>
                            <td>
                                <c:out value="${c.customerType}"/>
                            </td>
                            <td>
                                <c:out value="${c.vatNumber}"/>
                            </td>
                            <td>
                                <c:out value="${c.companyNumber}"/>
                            </td>
                            <td>
                                <a href="<c:url value="/customer/edit/${c.id}"/>">
                                    <img src="<c:url value="/resources/pictures/edit.png" />" title="<fmt:message key="edit" />" /> <fmt:message key="edit" />
                                </a>
                            </td>
                        </tr>
                    </c:forEach>
                </table>
            </c:if>
        </div>
    </body>
</html>
